# coding=utf-8
#


from multiprocessing import Pool

from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.cvm.v20170312 import cvm_client
from tencentcloud.cvm.v20170312 import models

TX_API_AK = "AKID53rSuDLG1Z6UeeTDpIcqwobCdt0ta7gm"
TX_API_SK = "51oSy38MeTD3sheicKtPkuvqlaCHExXw"


def delete_agents(endpoint, zone, server_list, *args, **kwargs):
#def delete_agents(params, *args, **kwargs):
    """ """
    print(endpoint, zone, server_list)
    cred = credential.Credential(TX_API_AK, TX_API_SK)

    httpProfile = HttpProfile()
    httpProfile.endpoint = endpoint

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = cvm_client.CvmClient(cred, zone, clientProfile)

    print(client, server_list)



def backend():

    server_list = [1,2,3,4,5,5,6,6,6,6,6,6,6,6,5,5,5,5,5,4,4,4,4,3,33,2,2,2]
    per_group = 5

    endpoint = "cvm.ap-beijing.tencentcloudapi.com"
    zone = "ap-beijing"

    results = []

    with Pool() as p:

        for instance_list in [server_list[i:i+per_group] for i in range(0, len(server_list), per_group)]:
            results = p.starmap(delete_agents, [(endpoint, zone, instance_list)])

        print(results)


backend()
